package com.xuecheng.teaching.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xuecheng.teaching.model.entity.TeachplanWork;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TeachplanWorkMapper extends BaseMapper<TeachplanWork> {
    
    /**
     * 查询课程计划绑定的作业
     * @param teachplanId 课程计划ID
     * @return 作业信息
     */
    @Select("SELECT tw.*, w.title, w.question " +
            "FROM teachplan_work tw " +
            "LEFT JOIN work w ON tw.work_id = w.work_id " +
            "WHERE tw.teachplan_id = #{teachplanId}")
    TeachplanWork selectByTeachplanId(@Param("teachplanId") Long teachplanId);
    
    /**
     * 查询课程绑定的所有作业
     * @param courseId 课程ID
     * @return 作业列表
     */
    @Select("SELECT tw.*, w.title, w.question " +
            "FROM teachplan_work tw " +
            "LEFT JOIN work w ON tw.work_id = w.work_id " +
            "WHERE tw.course_id = #{courseId}")
    List<TeachplanWork> selectByCourseId(@Param("courseId") Long courseId);

    //根据workId查询teachplan_work
    @Select("SELECT * FROM teachplan_work WHERE work_id = #{workId}")
    TeachplanWork selectByWorkId(@Param("workId") Long workId);
}